#!/usr/bin/python
# -*- coding: UTF-8 -*-


import sys
import os
import struct

class OTA_bin_build(object):
    def __init__(self,boot_file,boot_size,app_file):
    
        print(boot_file)
        print(boot_size)
        print(app_file)

        boot_file_op = open(boot_file, "rb")
        app_file_op = open(app_file, "rb")

        boot_file_size = os.path.getsize(boot_file)
        app_file_size = os.path.getsize(app_file)
        set_0xff_size = int(boot_size)*1024-boot_file_size

        pack_file_op = open("pack_file.bin", "wb")

        while True:
            content = boot_file_op.read(1024)
            if len(content) == 0:
                break
            pack_file_op.write(content)
            

        for i in range(set_0xff_size):
            s = struct.pack('B',0xFF)
            pack_file_op.write(s)

        while True:
            content = app_file_op.read(1024)
            if len(content) == 0:
                break
            pack_file_op.write(content)

        boot_file_op.close()
        app_file_op.close()
        pack_file_op.close()
        print(boot_file_size,set_0xff_size)
